package com.digitalxpert.jargle.client;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
public class JGFrame extends JFrame {
	private final String newline = "\n";
	private JPanel contentPane;
	private BorderLayout borderLayout1 = new BorderLayout();
	private JLabel status = new JLabel("JarGle");
	private JTextArea log;
	private File selDir;
	private JGFramePather view;
	public JGFrame() {
		try {
			jbInit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void jbInit() throws Exception {
		log = new JTextArea(5, 20);
		view = new JGFramePather(log);
		contentPane = (JPanel) this.getContentPane();
		contentPane.setLayout(borderLayout1);
		Border border = BorderFactory.createEtchedBorder(Color.white, new Color(178, 178, 178));
		status.setBorder(border);
		status.setOpaque(true);
		contentPane.add(status, BorderLayout.SOUTH);
		this.setSize(new Dimension(400, 300));
		this.setTitle("JarGle");
		JMenuBar menuBar = new JMenuBar();
		JMenu menuFile = new JMenu("File");
		menuFile.addMouseListener(new JGMouseAdapter("Menu file", " ", status));
		JMenuItem item1 = new JMenuItem("New app");
		item1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JDialog d = new JDialog();
				d.setTitle("Na xuy!!");
				d.setBounds(200, 200, 150, 20);
				d.setVisible(true);
			}
		});
		JMenuItem item2 = new JMenuItem("Open dir");
		item2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFileChooser fc = new JFileChooser();
				fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				int returnVal = fc.showOpenDialog(fc);
				if (returnVal == JFileChooser.APPROVE_OPTION) {
					selDir = fc.getSelectedFile();
					view.extractFiles(selDir);
				}
			}
		});
		JMenuItem item3 = new JMenuItem("Send to db");
		JMenuItem item4 = new JMenuItem("Reset");
		JMenuItem item5 = new JMenuItem("Exit");
		item5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		item1.setIcon(new ImageIcon(getToolkit().createImage("images/add.gif")));
		item2.setIcon(new ImageIcon(getToolkit().createImage("images/play.gif")));
		item3.setIcon(new ImageIcon(getToolkit().createImage("images/pause.gif")));
		item5.setIcon(new ImageIcon(getToolkit().createImage("images/delete.gif")));
		item1.addMouseListener(new JGMouseAdapter("New application", " ", status));
		item2.addMouseListener(new JGMouseAdapter("Open application directorie", " ", status));
		item3.addMouseListener(new JGMouseAdapter("Send to database", " ", status));
		item4.addMouseListener(new JGMouseAdapter("Reset", " ", status));
		item5.addMouseListener(new JGMouseAdapter("Exit prorgamm", " ", status));
		menuFile.add(item1);
		menuFile.addSeparator();
		menuFile.add(item2);
		menuFile.add(item3);
		menuFile.addSeparator();
		menuFile.add(item4);
		menuFile.addSeparator();
		menuFile.add(item5);
		menuBar.add(menuFile);
		this.setJMenuBar(menuBar);
		UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		SwingUtilities.updateComponentTreeUI(this);
		log.setMargin(new Insets(5, 5, 5, 5));
		log.setEditable(false);
		JScrollPane logScrollPane = new JScrollPane(log);
		long i = 2;
		Long j = 2L;
		// log.append(" 2 + 2: " + (i +j) + " " + (i==j) + newline);
		this.add(logScrollPane);
		/*
		 * addWindowListener(new WindowAdapter() { public void
		 * windowClosing(WindowEvent e) { System.out.println("Ku-KU");
		 * System.exit(0); } });
		 */
	}
	protected void processWindowEvent(WindowEvent e) {
		super.processWindowEvent(e);
		
		if (e.getID() == WindowEvent.WINDOW_CLOSING) {
			System.out.println("Ku-KU");
			System.exit(0);
		}
	}
}
